#ifndef HTTP_SERVER
#define HTTP_SERVER

#include <cstdint>
#include <memory>
#include <string>
#include "beast.hpp"
#include "net.hpp"


// Accepts incoming connections and launches the sessions
class HttpServer : public std::enable_shared_from_this<HttpServer>
{
public:
    HttpServer(std::string& address, uint16_t listenPort, std::size_t threadNum);
    // Start accepting incoming connections
    void run();

private:

    net::io_context ioc_;
    tcp::acceptor acceptor_;
    tcp::endpoint endpoint_;

    void fail(beast::error_code ec, char const* what);
    void on_accept(std::error_code ec, tcp::socket socket);
};

#endif //HTTP_SERVER
